package ai.yue.open.service.cd.controller;

import ai.yue.library.base.annotation.ApiVersion;
import ai.yue.library.base.ipo.ValidationGroups;
import ai.yue.library.base.view.Result;
import ai.yue.open.service.cd.ipo.WorkloadIPO;
import ai.yue.open.service.cd.service.WorkloadService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作负载
 *
 * @author yl-yue
 * @since  2023/2/14
 */
@ApiVersion
@RequiredArgsConstructor
@RestController
@RequestMapping("/auth/{version}/workload")
public class WorkloadController {

    final WorkloadService workloadService;

    @PostMapping("/insert")
    public Result<?> insert(WorkloadIPO workloadIPO) {
        return workloadService.insert(workloadIPO);
    }

    @DeleteMapping("/deleteById")
    public Result<?> deleteById(Long id) {
        return workloadService.deleteById(id);
    }

    @DeleteMapping("/deleteByIds")
    public Result<?> deleteByIds(List<Long> ids) {
        return workloadService.deleteByIds(ids);
    }

    @PutMapping("/updateById")
    public Result<?> updateById(@Validated(ValidationGroups.Update.class) WorkloadIPO workloadIPO) {
        return workloadService.updateById(workloadIPO);
    }

    @GetMapping("/page")
    public Result<?> page(String namespace) {
        // 前端需要传规范的分页参数，框架会自动从request中获取
        return workloadService.page(namespace);
    }

}
